<?php
$mod='blank';
include("../includes/common.php");
if(!$login) exit("<script language='javascript'>window.location.href='/login.php';</script>");
$type = $_GET['type'];
$uid = $userrow['id'];
if($type=="buyvip"){
	$vipprice = $conf['tell_m_vip_money'];
	if($userrow['money']<$vipprice){
		exit("<script language=\"javascript\">alert('余额不足,无法开通');history.go(-1);</script>");
		}else{
			$end = date("Y-m-d",strtotime("+ 31 days"));
			$sql = "update tell_users set vip=1,vipenddate='$end',money=money-$vipprice where id='$uid' limit 1";
			if($DB->query($sql)) exit("<script language=\"javascript\">alert('开通成功');history.go(-1);</script>");
			else exit("<script language=\"javascript\">alert('未知错误,开通失败');history.go(-1);</script>");
			}
}elseif($type=="uplevel"){
	$level = $userrow['agent']+1;
	if(!$dl = $DB->get_row("select * from tell_level where id='$level' limit 1")){
		exit("<script language=\"javascript\">alert('恭喜,您的代理级别已达最高级');history.go(-1);</script>");
		}
	$dlprice = $dl['buyprice'];
	if($userrow['money']<$dlprice){
		exit("<script language=\"javascript\">alert('余额不足,无法开通');history.go(-1);</script>");
		}else{
			$sql = "update tell_users set agent='$level',money=money-$dlprice where id='$uid' limit 1";
			if($DB->query($sql)) exit("<script language=\"javascript\">alert('开通成功');history.go(-1);</script>");
			else exit("<script language=\"javascript\">alert('未知错误,开通失败');history.go(-1);</script>");
			}
}
?>
